package com.tzbank.voice.controller;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;
import com.tzbank.voice.entity.VoiceModel;
import com.tzbank.voice.service.VoiceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api("TZBANK-AI:语音识别控制器")
@RestController
public class VoiceController {

	@Autowired
	VoiceService voiceService;

	/**
	 * 语音语义分析
	 * 
	 * @auther llz&wdj 2018/05/17
	 * @throws InterruptedException
	 */
	@ApiOperation(value = "intovoice", notes = "语音语义分析")
	@ApiImplicitParams({ @ApiImplicitParam(name = "auf", value = "音频格式（8k、16k）", paramType = "query", required = true),
			@ApiImplicitParam(name = "aue", value = "音频编码，可选值：raw", paramType = "query", required = true),
			@ApiImplicitParam(name = "scene", value = "情景模式", paramType = "query", required = true),
			@ApiImplicitParam(name = "spx_fsize", value = "speex 编码器对每帧音频（SPEEX_GET_FRAME_SIZE获取）进行编码压缩后的纯语音数据大小。", paramType = "query"),
			@ApiImplicitParam(name = "userid", value = "用户ID", paramType = "query", required = true),
			@ApiImplicitParam(name = "data", value = "Base64 编码的音频， 支持 pcm 或 wav 以及 speex 宽带压缩格式", paramType = "query", required = true),
			@ApiImplicitParam(name = "userid", value = "用户id", paramType = "query", required = true),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query", required = true) })
	@RequestMapping(value = "/intovoice", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> voiceTranslation(@RequestBody VoiceModel vo) {	
	
		// 判断参数是否为空
		if (StringUtils.isEmpty(vo.getData_type()) || StringUtils.isEmpty(vo.getData())) {	
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		
		return voiceService.voiceTranslation_v2(vo);

	}

}
